var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({
  data: {
    id: 0,
    name: '',
    mechanismName: '',
    discountsAddTime: '',
    discountsEndTime: '',
    buyAddTime: '',
    buyEndTime: '',
    retailPrice: '',
    number: 0,
    picUrl: '',
    desc: '',
    brief: '',
    showType: 1,
    orderSn: 0
  },
  onShow: function () {
    let that = this;
    util.request(api.MyVoucherDetail, {
      id: that.data.id
    })
    .then(function (res) {
      that.setData({
        name: res.data.goods.name,
        mechanismName: res.data.goods.mechanismName,
        discountsAddTime: res.data.goods.discountsAddTime,
        discountsEndTime: res.data.goods.discountsEndTime,
        buyAddTime: res.data.goods.buyAddTime,
        buyEndTime: res.data.goods.buyEndTime,
        retailPrice: res.data.goods.retailPrice,
        number: res.data.goods.number,
        picUrl: res.data.goods.picUrl,
        desc: res.data.goods.desc,
        brief: res.data.goods.brief
      });
    });
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    this.setData({
      id: parseInt(options.id),
      showType: parseInt(options.showType),
      orderSn: options.orderSn
    });
  },
  onUnload: function () {
    let that = this;
    this.setData({
      showType: that.data.showType
    });
  }
})
